<template>
  <!-- <div class="card"> -->
  <div class="card_out" ref="homePage">
    <div class="card">
      <p class="card_tit"></p>
      <div class="card_shell" v-for="item in list">
        <p class="card_title">{{item.title}}</p>
        <div class="card_main flex">
          <div class="card_left">
            <p class="card_subtit">已使用</p>
            <p class="card_used">{{item.already_num}}</p>
          </div>
          <div class="card_right">
            <p class="card_subtit">剩余次数</p>
            <p class="card_surplus">{{item.total_number - item.already_num}}</p>
          </div>
        </div>
        <p class="card_buytime">购卡日期：{{item.addtime}}</p>
      </div>
    </div>    
    <button class="card_btn" @click="back">返回首页</button>
  </div>

</template>

<script>
  import axios from 'axios';
  import global from '../../../utils/global'
  import store from '../../../utils/store'
  export default {
    name: 'Card',
    data () {
      return {
        // clientHeight:'',
        list: [],
        car: [
          {
            name: '轿车12次卡',
            used: '2',
            surplus: '10',
            buytime: '2018-01-01',
          },
          {
            name: 'SUV12次卡',
            used: '6',
            surplus: '6',
            buytime: '2018-04-01',
          },
        ],
      }
    },
    mounted(){
      this.clientHeight = `${document.documentElement.clientHeight}`
      window.onresize = function temp() {
        this.clientHeight = `${document.documentElement.clientHeight}`;
      };
      
      this.getInfo();

      this.$root.share();
    },
    watch: {
      clientHeight: function () {
        this.changeFixed(this.clientHeight)
      }
    },
    methods: {
      changeFixed(clientHeight){
        console.log(clientHeight);
        this.$refs.homePage.style.height = clientHeight+'px';
      },

      // 获取数据
      getInfo(){

        var that = this;

        axios.get(global.api.carCard.mycard,{
          params: {
            uuid: localStorage.getItem('carWashUuid'),
          }
        })

        .then(function(res){

          console.log("getInfo");
          console.log(res);
          that.list = res.data.data;

        })

        .catch(function(res){

          console.log("getInfo catch");
          console.log(res);

        })

      },

      // 返回首页
      back(){
        this.$router.push({path:'/'})
      },
    },
  }
</script>
  
<style scoped>
  .card_out{
    background-color: #EFEFEF;
    padding-bottom: 1rem;
    position: relative;
  }
  .card{
    background-color: #EFEFEF;
    /*padding-top: 1rem;*/
    text-align: left;
    padding-bottom: 3rem;
  }
  .card_tit{
    height: 1rem;
    line-height: 1rem;
  }
  .card_shell {
    width: 94%;
    margin: 0 auto 1rem;
    background-color: #fff;
    border-radius: 0.5rem;
    padding: 1rem 5%;
  }
  .card_shell:last-child{
    /*margin-bottom: 0;*/
  }
  .card_title {
    line-height: 2rem;
    padding-left: 0.5rem;
    border-bottom: 0.6rem solid #E4E4E6;
    margin-bottom: 0.5rem;
    font-weight: bold;
  }
  .card_main {
    padding-left: 0.5rem;
    line-height: 2.5rem;
  }
  .card_left,.card_right{
    -webkit-box-flex: 1;
    -webkit-flex: 1;
    flex: 1;
    text-align: center;
    border-bottom: 1px dashed #B3B3B4;
  }
  .card_subtit{

  }
  .card_used{
    font-size: 1.5rem;
  }
  .card_surplus{
    font-size: 1.5rem;
    color: #2ecc80;
  }
  .card_buytime{
    font-size: 0.8rem;
    color: #888888;
    padding: 0.5rem 0 0 1rem;
  }
  .card_btn{
    width: 90%;
    height: 2.5rem;
    line-height: 2.5rem;
    background-color: #19c674;
    color: #fff;
    border: none;
    border-radius: .5rem;
    margin: 1rem 0;
    font-size: .95rem;
    position: absolute;
    bottom: 0;
    left: 5%;
  }
</style> 
<style>
  ul,li,div,a,p,span{
    margin: 0;
    padding: 0;
  }
  li{
    list-style: none;
  }
  .flex{
    display: -webkit-box;
    display: -webkit-flex;
    display: flex;
  }
  .side_center{
    justify-content: space-between;
    align-items: center;
  }
  .start_center{
    justify-content: flex-start;
    align-items: flex-start;
  }
  .start_end{
    justify-content: flex-start;
    align-items: flex-end;
  }
</style>
